﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _14._03.CipherWithWord
{
    class Program
    {
        static string alphabet = "abcdefghijklmnopqrstuvwxyz";

        static void Main(string[] args)
        {
            Console.Write("Enter word for encryption: ");
            string wordToEncrypt = Console.ReadLine();
            Console.Write("Secret Word: ");
            string secredWord = Console.ReadLine();


            string result = string.Empty;

            for (int i = 0; i < wordToEncrypt.Length; i++)
            {
                char letterOfWordToEncrypt = wordToEncrypt[i];

                string newAplhabet = GenerateNewCeaserAlphabet(secredWord);

                int indexOfLetterOfWordToEnctypt = alphabet.IndexOf(letterOfWordToEncrypt);

                result += newAplhabet[indexOfLetterOfWordToEnctypt];
            }

            Console.WriteLine(result);

        }

        private static string GenerateNewCeaserAlphabet(string secretWord)
        {
            var alphabetWitoutSecredWordLetters = alphabet;

            foreach (char letter in secretWord)
            {
                alphabetWitoutSecredWordLetters = alphabetWitoutSecredWordLetters.Replace(letter.ToString(), "");
            }

            return secretWord + alphabetWitoutSecredWordLetters;
        }
    }
}
